package com.webserver.core;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/**
 * 该线程任务负责指定的客户端完成HTTP交互
 */
public class ClientHandler implements Runnable {
    private Socket socket;
    public ClientHandler(Socket socket){
        this.socket=socket;
    }
    @Override
    public void run() {
        try {
            InputStream is=socket.getInputStream();
            StringBuilder builder=new StringBuilder();
            int d;
            char pre='a',cur='a';
            while ((d=is.read())!=-1){
                cur=(char) d;
                if(pre==13&cur==10){
                   break;
                }
                builder.append(cur);
                pre=cur;
            }
            String str=builder.toString().trim();
            System.out.println(str);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
